import tkinter as tk
import threading
import time as tm


## 无聊的初始化 ##
top = tk.Tk()
top.title('clr')
l = tk.Label(top, width=20, height=2)
l.pack()

r = 100
g = 100
b = 100

## 数据格式化函数 ##
def ColorFormatting(r, g ,b):
	# r_ = str(hex(r))[2:].zfill(2)
	# g_ = str(hex(g))[2:].zfill(2)
	# b_ = str(hex(b))[2:].zfill(2)
	# clr = '#' + r_ + g_ + b_
	clr = '#'
	for i in [r, g ,b]:
		clr += str(hex(i))[2:].zfill(2)
	return clr

## 设置颜色函数 ##
def SetR(v):
	global r
	r = v
def SetG(v):
	global g
	g = v
def SetB(v):
	global b
	b = v

## 数据单位统一函数 ##
def Unit(*num):
	ns = []
	for i in range(len(num)):
		ns.append(num[i] * 2.55)
	if len(ns) == 1:
		return ns[0]
	else:
		return ns

## 创建tk条 ##
RL = tk.Label(top, text = "Red:")
RL.pack()
RS = tk.Scale(top, orient=tk.HORIZONTAL, from_=0, to=100)
RS.pack()
GL = tk.Label(top, text = "Green:")
GL.pack()
GS = tk.Scale(top, orient=tk.HORIZONTAL, from_=0, to=100)
GS.pack()
BL = tk.Label(top, text = "Blue:")
BL.pack()
BS = tk.Scale(top, orient=tk.HORIZONTAL, from_=0, to=100)
BS.pack()

def aaa(): 
	while True:
		tm.sleep(0.001)
		## 数据接收、转换 ##
		red = int(Unit(RS.get()))
		green = int(Unit(GS.get()))
		blue = int(Unit(BS.get()))
		clr = ColorFormatting(red, green, blue)

		## 数据应用 ##
		top.after(100)
		l.config(bg = clr, text=f'{red} {green} {blue}')
aa = threading.Thread(target=aaa)
aa.start()

## 收尾 ##
tk.mainloop()

# 制作流程
'''
导入
	tkinter
	time
初始化
	tkinter界面
	变量
	函数
背景应用(config(clr))
	每隔一段时间侦测一次(time.sleep())
	应用色号
收尾
	mainloop()
'''
# 附录
'''
tkinter.Scale(...)的应用方法:

var1 = tk.IntVar()
var2 = tk.IntVar()
scale1 = tk.Scale(
	top,
	orient=tk.VERTICAL,
	variable=var1,
	from_=0,
	to=10,
	length=300,
	command=OnSlide
)  # 竖
scale2 = tk.Scale(
	top,
	orient=tk.HORIZONTAL,
	variable=var2,
	from_=0,
	to=50,
	length=200
)  # 横
'''
